iOS转场动画-让你的页面app不再单调

fromView and toView

转场动画中时常会出现 fromView 和 toView 这一组相对的概念

fromView:跳转前的视图
toView:跳转后的视图

当然这两个视图是相对的,
比如A present to B ,此时 A = fromView , B = toView
然而B dismiss to A ,此时 B = fromView , A = toView
所以fromView和toView不是固定且一成不变的,会随着动画的执行和结束发生变化,扮演不同的角色

presentedViewController and presentingViewController

听过 fromView 和 toView ,想必 presentedViewController 和 presentingViewController也不会太陌生,这也是一组相对概念,而且容易与第一组混淆。

不同之处在于 presentedViewController 和 presentingViewController 的身份不受present影响,简单说还是上面的例子
比如A present to B ,此时 A = presentedViewController , B = presentingViewController
然而B dismiss to A ,此时 A = presentedViewController , B = presentingViewController

modalPresentationStyle

系统提供的一个present时动画的枚举类型

typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
        UIModalPresentationFullScreen = 0,
        UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
        UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
        UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS(3_2),
        UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS(7_0),
        UIModalPresentationOverFullScreen NS_ENUM_AVAILABLE_IOS(8_0),
        UIModalPresentationOverCurrentContext NS_ENUM_AVAILABLE_IOS(8_0),
        UIModalPresentationPopover NS_ENUM_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED,
        UIModalPresentationBlurOverFullScreen __TVOS_AVAILABLE(11_0) __IOS_PROHIBITED __WATCHOS_PROHIBITED,
        UIModalPresentationNone NS_ENUM_AVAILABLE_IOS(7_0) = -1,
};

其中可以自定义动画效果的只有两种:FullScreen和Custom,两者的区别在于FullScreen会移除fromView,而Custom不会。

UIViewControllerTransitioningDelegate

transitionFromViewController

通常的使用场景是 在多个Child ViewController之间切换.

[self transitionFromViewController:<#(nonnull uiviewcontroller="" *)#="">
                      toViewController:<#(nonnull uiviewcontroller="" *)#="">
                              duration:<#(nstimeinterval)#>
                               options:<#(uiviewanimationoptions)#>
                            animations:<#^(void)animations#>
                            completion:<#^(bool finished)completion#="">];
                            

上一篇
实用框架 实用框架
新闻选项卡1.新闻类的顶部选项卡类似网易新闻:WMPageController,HMSegmentControl,HTHorizontalSelectionList 这三者我跟推荐第一种,第一种有很多手势,比如点击顶部列表会滑动到最顶端。具
2018-04-02
下一篇
UICollectionView Layout自定义 Layout布局 UICollectionView Layout自定义 Layout布局
UICollectionView Layout自定义 Layout布局 #前言 要从容地着手去做一件事,但一旦开始,就要坚持到底。——比阿斯【美】对于UIcollectionView的基础使用相信各位早已烂熟于心,那么对于UICollect
2018-03-02
目录